package byte_stream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

//异常处理
// finally修饰的一定会执行,除非虚拟机退出
public class Demo04 {
    public static void main(String[] args) throws FileNotFoundException {
        //加入finally来实现释放资源     
        FileOutputStream fos = new FileOutputStream("heqiang06-io\\heqiang.txt");
        try {
            fos.write("hello".getBytes());
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}


